---
layout: "default"
title: "UnsafeRawPointer"
description: "Swift documentation for 'UnsafeRawPointer': A raw pointer for accessing untyped data. This provides no."
keywords: "UnsafeRawPointer,struct,swift,documentation,advanced,assumingMemoryBound,bindMemory,deallocate,distance,load,customMirror,customPlaygroundQuickLook,debugDescription,hashValue"
root: "/v3.0"
---

<div class="intro-declaration"><code class="language-swift">struct UnsafeRawPointer</code></div>

<div class="discussion comment">
    <p>A raw pointer for accessing untyped data. This provides no
automatic memory management, no type safety, and no alignment
guarantees. This implements Strideable to provide a view
of byte-addressable memory.</p>
</div>

<table class="standard">
<tr>
<th id="inheritance">Inheritance</th>
<td>
<code class="inherits">Comparable, CustomDebugStringConvertible, CustomPlaygroundQuickLookable, CustomReflectable, Equatable, Hashable, Strideable</code>
<span class="viz"><a href="hierarchy/">View Protocol Hierarchy &rarr;</a></span>
</td>
</tr>



<tr>
<th>Import</th>
<td><code class="language-swift">import Swift</code></td>
</tr>

</table>


<h3>Initializers</h3>
<div class="declaration" id="init_-opaquepointer">
<a class="toggle-link" data-toggle="collapse" href="#comment-init_-opaquepointer">init(<wbr>_: OpaquePointer)</a><div class="comment collapse" id="comment-init_-opaquepointer"><div class="p">
    <p>Converts an opaque pointer to an <code>UnsafeRawPointer</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">init(_ other: OpaquePointer)</code>

    </div></div>
</div>
<div class="declaration" id="init_-unsafemutablerawpointer">
<a class="toggle-link" data-toggle="collapse" href="#comment-init_-unsafemutablerawpointer">init(<wbr>_: UnsafeMutableRawPointer)</a><div class="comment collapse" id="comment-init_-unsafemutablerawpointer"><div class="p">
    <p>Converts an UnsafeMutableRawPointer to an <code>UnsafeRawPointer</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">init(_ other: UnsafeMutableRawPointer)</code>

    </div></div>
</div>
<div class="declaration" id="init_-unsaferawpointer">
<a class="toggle-link" data-toggle="collapse" href="#comment-init_-unsaferawpointer">init(<wbr>_: UnsafeRawPointer)</a><div class="comment collapse" id="comment-init_-unsaferawpointer"><div class="p">
    <p>Creates an <code>UnsafeRawPointer</code> from another <code>UnsafeRawPointer</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">init(_ other: UnsafeRawPointer)</code>

    </div></div>
</div>
<div class="declaration" id="init-t_-autoreleasingunsafemutablepointer-t">
<a class="toggle-link" data-toggle="collapse" href="#comment-init-t_-autoreleasingunsafemutablepointer-t">init&lt;T&gt;(<wbr>_: AutoreleasingUnsafeMutablePointer&lt;T&gt;)</a><div class="comment collapse" id="comment-init-t_-autoreleasingunsafemutablepointer-t"><div class="p">
    <p>Convert other <code>AutoreleasingUnsafeMutablePointer</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">init&lt;T&gt;(_ other: AutoreleasingUnsafeMutablePointer&lt;T&gt;)</code>

    </div></div>
</div>
<div class="declaration" id="init-t_-unsafemutablepointer-t">
<a class="toggle-link" data-toggle="collapse" href="#comment-init-t_-unsafemutablepointer-t">init&lt;T&gt;(<wbr>_: UnsafeMutablePointer&lt;T&gt;)</a><div class="comment collapse" id="comment-init-t_-unsafemutablepointer-t"><div class="p">
    <p>Converts an UnsafeMutablePointer to an <code>UnsafeRawPointer</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">init&lt;T&gt;(_ other: UnsafeMutablePointer&lt;T&gt;)</code>

    </div></div>
</div>
<div class="declaration" id="init-t_-unsafepointer-t">
<a class="toggle-link" data-toggle="collapse" href="#comment-init-t_-unsafepointer-t">init&lt;T&gt;(<wbr>_: UnsafePointer&lt;T&gt;)</a><div class="comment collapse" id="comment-init-t_-unsafepointer-t"><div class="p">
    <p>Converts an UnsafePointer to an <code>UnsafeRawPointer</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">init&lt;T&gt;(_ other: UnsafePointer&lt;T&gt;)</code>

    </div></div>
</div>
<div class="declaration" id="init_-opaquepointer">
<a class="toggle-link" data-toggle="collapse" href="#comment-init_-opaquepointer">init?(<wbr>_: OpaquePointer?)</a><div class="comment collapse" id="comment-init_-opaquepointer"><div class="p">
    <p>Converts an opaque pointer to an <code>UnsafeRawPointer</code>.</p>

<p>Returns <code>nil</code> if <code>from</code> is <code>nil</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">init?(_ other: OpaquePointer?)</code>

    </div></div>
</div>
<div class="declaration" id="init_-unsafemutablerawpointer">
<a class="toggle-link" data-toggle="collapse" href="#comment-init_-unsafemutablerawpointer">init?(<wbr>_: UnsafeMutableRawPointer?)</a><div class="comment collapse" id="comment-init_-unsafemutablerawpointer"><div class="p">
    <p>Converts an UnsafeMutableRawPointer to an <code>UnsafeRawPointer</code>.</p>

<p>Returns <code>nil</code> if <code>other</code> is <code>nil</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">init?(_ other: UnsafeMutableRawPointer?)</code>

    </div></div>
</div>
<div class="declaration" id="init_-unsaferawpointer">
<a class="toggle-link" data-toggle="collapse" href="#comment-init_-unsaferawpointer">init?(<wbr>_: UnsafeRawPointer?)</a><div class="comment collapse" id="comment-init_-unsaferawpointer"><div class="p">
    <p>Creates an <code>UnsafeRawPointer</code> from another <code>UnsafeRawPointer</code>.</p>

<p>Returns <code>nil</code> if <code>other</code> is <code>nil</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">init?(_ other: UnsafeRawPointer?)</code>

    </div></div>
</div>
<div class="declaration" id="init-t_-autoreleasingunsafemutablepointer-t">
<a class="toggle-link" data-toggle="collapse" href="#comment-init-t_-autoreleasingunsafemutablepointer-t">init?&lt;T&gt;(<wbr>_: AutoreleasingUnsafeMutablePointer&lt;T&gt;?)</a><div class="comment collapse" id="comment-init-t_-autoreleasingunsafemutablepointer-t"><div class="p">
    <p>Convert other <code>AutoreleasingUnsafeMutablePointer</code>.</p>

<p>Returns nil if <code>other</code> is nil.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">init?&lt;T&gt;(_ other: AutoreleasingUnsafeMutablePointer&lt;T&gt;?)</code>

    </div></div>
</div>
<div class="declaration" id="init-t_-unsafemutablepointer-t">
<a class="toggle-link" data-toggle="collapse" href="#comment-init-t_-unsafemutablepointer-t">init?&lt;T&gt;(<wbr>_: UnsafeMutablePointer&lt;T&gt;?)</a><div class="comment collapse" id="comment-init-t_-unsafemutablepointer-t"><div class="p">
    <p>Converts an UnsafeMutablePointer to an <code>UnsafeRawPointer</code>.</p>

<p>Returns <code>nil</code> if <code>other</code> is <code>nil</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">init?&lt;T&gt;(_ other: UnsafeMutablePointer&lt;T&gt;?)</code>

    </div></div>
</div>
<div class="declaration" id="init-t_-unsafepointer-t">
<a class="toggle-link" data-toggle="collapse" href="#comment-init-t_-unsafepointer-t">init?&lt;T&gt;(<wbr>_: UnsafePointer&lt;T&gt;?)</a><div class="comment collapse" id="comment-init-t_-unsafepointer-t"><div class="p">
    <p>Converts an UnsafePointer to an <code>UnsafeRawPointer</code>.</p>

<p>Returns <code>nil</code> if <code>other</code> is <code>nil</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">init?&lt;T&gt;(_ other: UnsafePointer&lt;T&gt;?)</code>

    </div></div>
</div>
<div class="declaration" id="init-bitpattern_-int">
<a class="toggle-link" data-toggle="collapse" href="#comment-init-bitpattern_-int">init?(<wbr>bitPattern: Int)</a><div class="comment collapse" id="comment-init-bitpattern_-int"><div class="p">
    <p>Converts a pattern of bits to an <code>UnsafeRawPointer</code>.</p>

<p>Returns <code>nil</code> if <code>bitPattern</code> is zero.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">init?(bitPattern: Int)</code>

    </div></div>
</div>
<div class="declaration" id="init-bitpattern_-uint">
<a class="toggle-link" data-toggle="collapse" href="#comment-init-bitpattern_-uint">init?(<wbr>bitPattern: UInt)</a><div class="comment collapse" id="comment-init-bitpattern_-uint"><div class="p">
    <p>Converts a pattern of bits to an <code>UnsafeRawPointer</code>.</p>

<p>Returns <code>nil</code> if <code>bitPattern</code> is zero.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">init?(bitPattern: UInt)</code>

    </div></div>
</div>


<h3>Instance Variables</h3>
<div class="declaration" id="var-custommirror_-mirror">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-custommirror_-mirror">var customMirror: Mirror</a><div class="comment collapse" id="comment-var-custommirror_-mirror"><div class="p">
    <p>The custom mirror for this instance.</p>

<p>If this type has value semantics, the mirror should be unaffected by
subsequent mutations of the instance.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">var customMirror: Mirror { get }</code>

    </div></div>
</div>
<div class="declaration" id="var-customplaygroundquicklook_-playgroundquicklook">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-customplaygroundquicklook_-playgroundquicklook">var customPlaygroundQuickLook: PlaygroundQuickLook</a><div class="comment collapse" id="comment-var-customplaygroundquicklook_-playgroundquicklook"><div class="p">
    <p>A custom playground Quick Look for this instance.</p>

<p>If this type has value semantics, the <code>PlaygroundQuickLook</code> instance
should be unaffected by subsequent mutations.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">var customPlaygroundQuickLook: PlaygroundQuickLook { get }</code>

    </div></div>
</div>
<div class="declaration" id="var-debugdescription_-string">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-debugdescription_-string">var debugDescription: String</a><div class="comment collapse" id="comment-var-debugdescription_-string"><div class="p">
    <p>A textual representation of the pointer, suitable for debugging.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">var debugDescription: String { get }</code>

    </div></div>
</div>
<div class="declaration" id="var-hashvalue_-int">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-hashvalue_-int">var hashValue: Int</a><div class="comment collapse" id="comment-var-hashvalue_-int"><div class="p">
    <p>The pointer&#39;s hash value.</p>

<p>The hash value is not guaranteed to be stable across different
invocations of the same program.  Do not persist the hash value across
program runs.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">var hashValue: Int { get }</code>

    </div></div>
</div>



<h3>Instance Methods</h3>
<div class="declaration" id="func-advanced-by_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-advanced-by_">func advanced(<wbr>by:)</a>
        
<div class="comment collapse" id="comment-func-advanced-by_"><div class="p">
    <p>Returns <code>self + n</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func advanced(by n: Int) -&gt; UnsafeRawPointer</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-assumingmemorybound_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-assumingmemorybound_">func assumingMemoryBound(<wbr>_:)</a>
        
<div class="comment collapse" id="comment-func-assumingmemorybound_"><div class="p">
    <p>Converts from an <code>UnsafeRawPointer</code> to UnsafePointer&lt;T&gt; given that
the region of memory starting at <code>self</code> is already bound to type <code>T</code>.</p>

<p><strong>Precondition:</strong> The memory is bound to &#39;T&#39; starting at <code>self</code> for some
  unspecified capacity.</p>

<p><strong>Warning:</strong> Accessing memory via the returned pointer is undefined if the
  if the memory has not been bound to <code>T</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func assumingMemoryBound&lt;T&gt;(to: T.Type) -&gt; UnsafePointer&lt;T&gt;</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-bindmemory-to_capacity_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-bindmemory-to_capacity_">func bindMemory(<wbr>to:<wbr>capacity:)</a>
        
<div class="comment collapse" id="comment-func-bindmemory-to_capacity_"><div class="p">
    <p>Binds the allocated memory to type <code>T</code> and returns an
<code>UnsafePointer&lt;T&gt;</code> to the bound memory at <code>self</code>.</p>

<p><strong>Precondition:</strong> The memory is uninitialized.
<strong>Postcondition:</strong> The memory is bound to &#39;T&#39; starting at <code>self</code> continuing
  through <code>self</code> + <code>count</code> * <code>MemoryLayout&lt;T&gt;.stride</code>
<strong>Warning:</strong> A memory location may only be bound to one type at a time.
  The behavior of accessing memory as type <code>U</code> while it is bound to an
  unrelated type <code>T</code> is undefined.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func bindMemory&lt;T&gt;(to type: T.Type, capacity count: Int) -&gt; UnsafePointer&lt;T&gt;</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-deallocate_alignedto_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-deallocate_alignedto_">func deallocate(<wbr>_:<wbr>alignedTo:)</a>
        
<div class="comment collapse" id="comment-func-deallocate_alignedto_"><div class="p">
    <p>Deallocates uninitialized memory allocated for <code>bytes</code> number of bytes
with <code>alignedTo</code> alignment.</p>

<p><strong>Precondition:</strong> The memory is not initialized.
<strong>Postcondition:</strong> The memory has been deallocated.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func deallocate(bytes: Int, alignedTo: Int)</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-distance-to_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-distance-to_">func distance(<wbr>to:)</a>
        
<div class="comment collapse" id="comment-func-distance-to_"><div class="p">
    <p>Returns <code>x - self</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func distance(to x: UnsafeRawPointer) -&gt; Int</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-load-frombyteoffset_as_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-load-frombyteoffset_as_">func load(<wbr>fromByteOffset:<wbr>as:)</a>
        
<div class="comment collapse" id="comment-func-load-frombyteoffset_as_"><div class="p">
    <p>Reads raw bytes from memory at <code>self + offset</code> and constructs a
value of type <code>T</code>.</p>

<p><strong>Precondition:</strong> The underlying pointer plus <code>offset</code> is properly
  aligned for accessing <code>T</code>.</p>

<p><strong>Precondition:</strong> The memory is initialized to a value of some type, <code>U</code>,
  such that <code>T</code> is layout compatible with <code>U</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func load&lt;T&gt;(fromByteOffset offset: Int = default, as type: T.Type) -&gt; T</code>
    
    
</div></div>
</div>


